<style>
	.layui-form-label{width: 90px;}
</style>
<div class="main">
	<div class="container">
		<div style="background:#fff;min-height: 800px; margin: 20px 0;display: flex;">
			<div class="user_center_left">
				{include file="common/sidenav"}
			</div>
			<div class="user_center_right">
				<div class="user_center_right_hd">
					升级成企业
				</div>
				<div class="user_center_right_bd" style="display: flex;align-items: center;justify-content: center;">
					<div class="center_form" style="width: 700px;">
						<form class="layui-form" action="">
							<div class="layui-form-item">
								<label class="layui-form-label">企业logo</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-xs layui-btn-normal" id="ID-upload-demo-btn">点击上传</button>
									<img id="logo_img" class="layui-upload-img" src="" style="width:100px;height:auto;">
									<input type="hidden" id="logo" value="">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">企业名称</label>
								<div class="layui-input-block">
									<input type="text" name="name" id="name" lay-verify="required"
										placeholder="请输入" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">企业电话</label>
								<div class="layui-input-block">
									<input type="text" name="tel" id="tel" lay-verify="required"
										placeholder="请输入" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">企业网址</label>
								<div class="layui-input-block">
									<input type="text" id="netaddress" lay-verify="required"
										placeholder="请输入" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">企业邮箱</label>
								<div class="layui-input-block">
									<input type="text" id="email" lay-verify="required"
										placeholder="请输入" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">企业地址</label>
								<div class="layui-input-block">
									<input type="text" id="address" lay-verify="required"
										placeholder="请输入" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">企业简介</label>
								<div class="layui-input-block">
									<textarea id="textarea2" class="layui-textarea"></textarea>
								</div>
							</div>
						</form>
						<div class="btn" style="margin-top:30px;">
							<button type="button"
								class="layui-btn layui-btn-lg layui-btn-fluid layui-btn-normal layui-btn-radius"
								onclick="submit()">保存</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	var layer;
	layui.use(function(){
		  var upload = layui.upload;
		  layer = layui.layer;
		  var element = layui.element;
		  var $ = layui.$;
		  // 单图片上传
		  var uploadInst = upload.render({
	        elem: '#ID-upload-demo-btn',
	        url: '/api.php/common/upload', // 实际使用时改成您自己的上传接口即可。
	        before: function(obj){
	          // 预读本地文件示例，不支持ie8
	          obj.preview(function(index, file, result){
	            $('#logo_img').attr('src', result); // 图片链接（base64）
	          });
	          
	          //layer.msg('上传中', {icon: 16, time: 0});
	        },
	        done: function(res){
	            console.log(res);
	          // 若上传失败
	          if(res.code!=1){
	            return layer.msg(res.msg);return false;
	          }
	          // 上传成功的一些操作
	          $('#logo').val(res.data.url);
	        }
	        
	      });
		  
		});
		
	function submit(){
	    if($('#logo').val().trim()==''){
	        layer.msg('请上传企业logo', {icon: 5});
	        return false;
	    }
	    if($('#name').val().trim()==''){
	        layer.msg('请填写企业名称', {icon: 5});
	        return false;
	    }
	    if($('#tel').val().trim()==''){
	        layer.msg('请输入企业电话', {icon: 5});
	        return false;
	    }
	    if($('#email').val().trim()==''){
	        layer.msg('请输入企业邮箱', {icon: 5});
	        return false;
	    }
	    if($('#address').val().trim()==''){
	        layer.msg('请输入企业地址', {icon: 5});
	        return false;
	    }
	    if($('#textarea2').val().trim()==''){
	        layer.msg('请输入企业简介', {icon: 5});
	        return false;
	    }
	    $.ajax({
	      type:"POST",
	      url:"/api.php/index/submit_becompany",
	      dataType:"json",
	      data:{
	          "logo":$('#logo').val(),
	          "name":$('#name').val(),
	          "tel":$('#tel').val(),
	          "email":$('#email').val(),
	          "netaddress":$('#netaddress').val(),
	          "address":$('#address').val(),
	          "content":$('#textarea2').val(),
	      },
	      success:function(res){
	          console.log(res);
	
	          if(res.code==0){
	              layer.msg(res.msg,{icon:5});
	
	          }else{
	              layer.msg(res.msg,{icon:6},function(){
	
					  window.location.href="{:url('user/become_company_result')}?id="+res.data.id;
	              });
	          }
	      }
	    });
	}	
</script>